package com.san.serviceImpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzk.utils.MD5Util;
import com.hzk.utils.UUIDUtil;
import com.hzk.vo.CaseUser;
import com.san.mapper.UserBasicMapper;
import com.san.pojo.UserBasic;
import com.san.service.IUserBasicService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jack
 * @since 2022-04-14
 */
@Service
public class UserBasicServiceImpl extends ServiceImpl<UserBasicMapper, UserBasic> implements IUserBasicService {
    @Autowired
    RedisTemplate redisTemplate;
    @Override
    public String getpath(@CaseUser com.hzk.pojo.UserBasic userBasic, Long goodsId, String t) {

        String token = t.substring(4);
        /*Object o = redisTemplate.opsForValue().get("UserBasic:" + token);*/
        String str="/ms"+MD5Util.formPassToDBPass(UUIDUtil.uuid().substring(0, 6),UUIDUtil.uuid().substring(0, 6)) ;
        redisTemplate.opsForValue().set("seckillPath:" + userBasic.getId() + ":" + goodsId, str, 60, TimeUnit.SECONDS);
        return str;
    }


    @Override
    public boolean checkPath(@CaseUser com.hzk.pojo.UserBasic user, Long goodsId, String path) {
        if (user == null || StringUtils.isEmpty(path)) {
            return false;
        }
        String redisPath = (String) redisTemplate.opsForValue().get("seckillPath:" + user.getId() + ":" + goodsId);
        return path.equals(redisPath);
    }
}
